<%--
  Created by IntelliJ IDEA.
  User: xiaomage
  Date: 2017/6/3
  Time: 9:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
  String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="en">
<head>
  <jsp:include page="/control/home/home_header.jsp"/>
    <style type="text/css">
        table.gridtable {
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            color:#333333;
            border-width: 1px;
            border-color: #e1e1e1;
            border-collapse: collapse;
        }
        table.gridtable th {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #dedede;
        }
        table.gridtable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #e1e1e1;
            background-color: #ffffff;
        }
        button {
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        }
    </style>
    <script src="<%=path%>/control/merchant/laydate-v1.1/laydate/laydate.js"></script>
</head>

<body>

<jsp:include page="/control/home/home_navbar.jsp"/>

<div class="main-container" id="main-container">
  <script type="text/javascript">
    try {
      ace.settings.check('main-container', 'fixed')
    } catch (e) {
    }
  </script>

  <div class="main-container-inner">
    <a class="menu-toggler" id="menu-toggler" href="#">
      <span class="menu-text"></span>
    </a>

    <jsp:include page="/control/home/home_navigation.jsp"/>

      <div>
          <table class="gridtable">
              <tr>
                  <td colspan="2">
                      开始时间: <input type="text" id="startTime"readonly="readonly" onclick="laydate()" />
                      &nbsp;&nbsp; 结束时间: <input type="text" id="endTime" readonly="readonly" onclick="laydate()" />
                  </td>
                  <td>
                      <input style="color: #666;background-color:#EEE " type="button" value="导出EXCLE"  onclick="getExcel();" />
                  </td>
              </tr>

              <tr>
                  <td> 交易类型:
                      <select 　id="paymentTypeName" name="paymentTypeName" onchange="onPtName(this.value);"  style="width:210px;">
                          <option value="" selected >请选择.......</option>
                          <option value ="PAUT">预下单</option>
                          <option value ="WPAY">H5支付</option>
                      </select>
                  </td>
                  <td> 渠&nbsp;&nbsp;&nbsp;&nbsp;道:
                      <select 　id="chcdName" name="chcdName"  onchange="onChName(this.value);"  style="width:210px;">
                          <option value="" selected >请选择.......</option>
                          <option value ="ALP">支付宝</option>
                          <option value ="WXP">微信</option>
                      </select>
                  </td>
                  <td>
                      交易结果:
                      <select 　id="respcd" name="respcd"  onchange="onReName(this.value);"  style="width:210px;">
                          <option value="" selected >请选择.......</option>
                          <option value ="00">交易成功</option>
                          <option value ="Y9">订单已关闭或取消</option>
                          <option value ="YA">字段名不能为空</option>
                          <option value ="YK">只能撤销当天交易</option>
                          <option value ="19">交易失败(19)</option>
                          <option value ="09">交易处理中</option>
                          <--<option value ="H5">H5下单未支付</option>-->
                          <option value ="YG">原交易已退款</option>
                          <option value ="YB">交易失败(YB)</option>
                      </select>
                  </td>
              </tr>
              <tr>
                  <td>  &nbsp;&nbsp;订单号: <input type="text" id="origOrderNum"  /> </td>
                  <td>  &nbsp;收款人: <input type="text" id="terminalid"   /></td>
                  <td>
                      <input style="color: #666;background-color:#EEE "  type="button" value="查&nbsp;&nbsp;&nbsp;&nbsp;询" onclick="searchbyDate();" />
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <input style="color: #666;background-color:#EEE " type="button" value="重&nbsp;&nbsp;&nbsp;&nbsp;置" onclick="restfrom();" />
                  </td>
              </tr>
              <tr>

                  <td colspan="3">
                     <div id="NumContent"></div>
                  </td>
              </tr>
          </table>




      </div>

    <div class="row">
      <div class="col-xs-12">
        <table id="grid-table"></table>

        <div id="grid-pager"></div>

        <script type="text/javascript">
          var $path_base = "/";//this will be used in gritter alerts containing images
        </script>

        <!-- PAGE CONTENT ENDS -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->


  </div>
  <!-- /.page-content -->
</div>
<!-- /.main-content -->

<%--<jsp:include page="/control/home/home_settings.jsp"/>--%>

</div>
<!-- /.main-container-inner -->

<jsp:include page="/control/home/home_scroll_top.jsp"/>

</div><!-- /.main-container -->

<jsp:include page="/control/home/home_footer.jsp"/>

<!-- page specific plugin scripts -->
<script src="<%=path%>/control/merchant/merchanttransaction_list_info.js"></script>
<script type="text/javascript">
    var paymentTypeName="";
    var chcdName="";
    var respcd="";
    var paramstr="";
    function onPtName(pname){//获取对应下拉框的值
        paymentTypeName=pname;
    }
    function onChName(cname){//获取对应下拉框的值
        chcdName=cname;
    }
    function onReName(rname){//获取对应下拉框的值
        respcd=rname;
    }
    function  restfrom(){//清空表单
        paramstr="";
        getCountnum();//再次统计
        var turl=cochoApp.baseUrl + "/admin/merchant/getMerchantTransactionInfo.do?token=" + cochoApp.getTokenByStorage();
        $("#startTime").val("");
        $("#endTime").val("");
        $("#terminalid").val("");
        $("#paymentTypeName");
        $("select").prop('selectedIndex', 0);//重置下拉框
        $("#origOrderNum").val("");
        $("#grid-table").jqGrid("setGridParam", {url:turl,datatype:"json"}).trigger("reloadGrid",[{page:1}]);
    }
    function getParams(){
        var terminalid=$.trim($("#terminalid").val());
        var origOrderNum=$.trim($("#origOrderNum").val());
        var date1 = $.trim($("#startTime").val());
        var date2 =$.trim($("#endTime").val());
        if(date1!=null&&date1!=''&&date2!=null&&date2!=''){//时间不空
            var  dat1=new Date(date1);
            var  dat2=new Date(date2);
            paramstr+="&startTime=";
            paramstr+=date1;
            paramstr+="&endTime=";
            paramstr+=date2;
        }
        if(terminalid!=null&&terminalid!=""){
            paramstr+="&terminalid=";
            paramstr+=terminalid;
        }
        //console.log(paymentTypeName+"||"+chcdName);
        if(paymentTypeName!=null&&paymentTypeName!=""){
            paramstr+="&paymentTypeName=";
            paramstr+=paymentTypeName;
        }
        if(chcdName!=null&&chcdName!=""){
            paramstr+="&chcdName=";
            paramstr+=chcdName;
        }
        if(respcd!=null&&respcd!=""){
            paramstr+="&respcd=";
            paramstr+=respcd;
        }
        if(origOrderNum!=null&&origOrderNum!=""){
            paramstr+="&origOrderNum=";
            paramstr+=origOrderNum;
        }
         console.log(paramstr);
    }
    function getExcel(){
        var eurl=cochoApp.baseUrl + "/admin/merchant/getExcelMerchantTransactionInfo.do?token=" + cochoApp.getTokenByStorage();
        eurl+=paramstr;
       // console.log("eurl="+eurl);
       // paramstr="";//清空参数
        window.open(eurl);
    }
    function searchbyDate(){
        var purl=cochoApp.baseUrl + "/admin/merchant/getMerchantTransactionInfo.do?token=" + cochoApp.getTokenByStorage();
        var date1 = $.trim($("#startTime").val());
        var date2 =$.trim($("#endTime").val());
        if(date1!=null&&date1!=''&&date2!=null&&date2!=''){//时间不空
            var  dat1=new Date(date1);
            var  dat2=new Date(date2);
            if(dat1.getTime()>=dat2.getTime()){//开始时间不能大于结束时间
                $('#startTime').focus();//重新设置时间
                alert("请正确选择开始时间");
                return;
            }
        }
        paramstr="";//清空参数
        getParams();//再拼接参数
        purl+=paramstr;
        //console.log("purl="+purl);
        getCountnum();//再次统计

        $("#grid-table").jqGrid("setGridParam", {url:purl,datatype:"json"}).trigger("reloadGrid",[{page:1}]);
    }
    function getCountnum() {
        var curl=cochoApp.baseUrl + "/admin/merchant/getMerchantTransactionInfoAll.do?token=" + cochoApp.getTokenByStorage();
        curl+=paramstr;
       // console.log("curl="+curl);
       // paramstr="";//清空参数
        var paramData = {};
        $.ajax({
            type: "post",
            async: true,//异步，如果等于false 那么就是同步
            url: curl,
            dataType: "json",
            data: paramData,
            success: function (data) {
                if (data != null) {
                    if (data.statusCode == "SUCCESS") {
                        CountSuccess(data);
                    } else {
                       // alert(data.statusMsg);
                        return false;
                    }
                } else {
                   // alert("登录失败,请联系管理员解决！");
                    return false;
                }
            },
            error: function (data) {
                //alert("请求服务器出错！");
                return false;
            }
        });
    }
    function CountSuccess(data) {

        var  loadMoreBtn = data.dataRows[0];

        if(loadMoreBtn==null || loadMoreBtn.length==0){
            //cochoAlert.notificationsWarn("已全部加载。");
            //alert("没有数据了。"); <span style="color: red;"></span>
        }
      //  console.log(loadMoreBtn.length);

        if (loadMoreBtn != null && loadMoreBtn.length > 0) {
            var sttp="";
            for (var i = 0; i < loadMoreBtn.length; i++) {
                var module = loadMoreBtn[i];
              //  console.log(module);
               // alert(module.codename);
                if(module.respcd=='00'){
                    sttp+="&nbsp;&nbsp;&nbsp;&nbsp;<span style='color: green;'>";
                    sttp+=module.codename;
                    sttp+="合计:";
                    sttp+=module.typeNum;
                    sttp+="</span>&nbsp;&nbsp;&nbsp;&nbsp;";
                }else{
                    sttp+="&nbsp;&nbsp;&nbsp;&nbsp;<span style='color: red;'>";
                    sttp+=module.codename;
                    sttp+="合计:";
                    sttp+=module.typeNum;
                    sttp+="</span>&nbsp;&nbsp;&nbsp;&nbsp;";
                }
               $('#NumContent').html(sttp);
            }
        }
    }
    getParams();
    setTimeout("getCountnum()",800);
</script>
</body>
</html>
